import {
  DeleteOneSessionDocument,
  DeleteOneSessionInput,
  PrivateInstanceNearbyMutation,
  SessionQuery,
} from './../../generated/graphql'
// openstack 的创建一些操作

import {
  CreateOneSessionDocument,
  CreateOneSessionInput,
  MyInfoDocument,
  MyInfoQuery,
  PrivateInstanceNearbyDocument,
  SessionDocument,
} from '@/generated/graphql'
import { Client } from '@urql/vue'

class OpenstackServices {
  client: Client

  constructor(client: Client) {
    this.client = client
  }

  //查询有哪些实例可以使用
  private_instance_nearby(params: string[]) {
    return this.client
      .mutation<PrivateInstanceNearbyMutation>(PrivateInstanceNearbyDocument, {
        instanceTypes: params,
      })
      .toPromise()
  }

  //创建一个session(对于openstack 即是绑定openstack到sesssion)
  create_one_session(data: CreateOneSessionInput) {
    return this.client
      .mutation(CreateOneSessionDocument, {
        data,
      })
      .toPromise()
  }

  //删除一个session
  delete_one_session(data: DeleteOneSessionInput) {
    return this.client
      .mutation(DeleteOneSessionDocument, {
        data,
      })
      .toPromise()
  }

  //查询登录用户的信息
  me() {
    return this.client.query<MyInfoQuery>(MyInfoDocument).toPromise()
  }

  //获取指定用户的session
  get_session(userId: string) {
    return this.client
      .query<SessionQuery>(SessionDocument, {
        where: {
          userId,
        },
      })
      .toPromise()
  }
}
export { OpenstackServices }
